<%--
 *  File:    MonthSalesDataTwo.jsp
 *  @Author: JackYin
 *  Date:    2011.1.11

 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>
<%@ page import="java.text.*" %>
<%
Category cat = Category.getInstance("jsp.MonthSalesDataTwo");
String strModuleName = "COM";
String privilegeCode = "A0116";
String strTableName = "v_zylmonthsalesdatatwo";
String contextPath = request.getContextPath();
%>
<%@ include file="/inc/CommonHeader.inc" %>
<%@ include file="/inc/OvalLocationDefault.inc" %>
<%@ include file="/rpt/ReportURL.inc" %>
<html>
<head>
<title>MonthSalesDataSummary</title>
<PageFlow:CheckPageFlow pageName="p_zylmonthsalesdatatwo"/>
<%
Vector searchresults = (Vector)pageContext.getAttribute("searchresults");
if(searchresults == null) searchresults = new Vector();
String endday = (String)pageContext.getAttribute("endday");
HashMap userinfo = (HashMap)session.getAttribute("userinfo");
Integer  issalesman = (Integer) userinfo.get("issalesman");
Integer  deptid = (Integer) userinfo.get("deptid");
java.util.Calendar cal = java.util.Calendar.getInstance();      
int day = cal.get(Calendar.DAY_OF_MONTH);
String  strdeptid =deptid+"";
String dateFormat = (String)session.getAttribute("dateformat");
if(dateFormat==null)dateFormat = "yyyy-MM-dd";
%>
<%@ include file="/inc/CatchError.inc" %>
<%@ include file="/inc/SumDiv.inc" %>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=contextPath%>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath%>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/ScriptLib.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/SummaryDivision.js"></script>
<script language="JavaScript" src="<%=contextPath%>/js/Calendar.js"></script>
<%@ include file ="/inc/NewCalendar.inc" %>
<script language="JavaScript">
//xuanze
function popDealer() {
	  opt = "dealer";
	  var status = "height=450, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
			var url = "PathOrgSelect.jsp?o_thread=" + Math.random();
			url += "&globalpccode=112,113,114,117";
			if (typeof popwindow != 'undefined') popwindow.close();
			popwindow = window.open(url, "newwindow", status);
	}
	
	function popCustomer() {
	  opt = "customer";
	  var status = "height=450, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no";
			var url = "PathOrgSelect.jsp?o_thread=" + Math.random();
			url += "&globalpccode=99,112,117";
			
			if (typeof popwindow != 'undefined') popwindow.close();
			popwindow = window.open(url, "newwindow", status);
	}
	function page_setOrg(id, name, code) {
	  if(opt == "dealer"){
	  	cform.dealerid.value=id;
	  	cform.dealercode.value = code;
	  	cform.dealername.value = name;
	  }
	  if(opt == "customer"){
	  	cform.customerid.value=id;
	  	cform.customercode.value = code;
	  	cform.customername.value = name;
	  }	
	  opt = "";
	  if (popwindow != null)
	    popwindow.close();
	}


//salesman
function popRep() {
	//var regionid=cform.regionid.value;
	//var proviceofficecode = cform.proviceofficelist.value;
	//var businessareacode = cform.businessarealist.value;
	//alert(regionid+"|"+proviceofficecode+"|"+businessareacode+"|");
	var status = "height=400, width=600, top=100, left=100, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no";
	var url = "<%=contextPath%>/tdr/dataverify/SalesPopWindow.jsp?<%= OvalTools.randomURL() %>";
	popwindow = window.open(url, "newwindow", status);
  }

function SetSalesMan(id,code,name){
	cform.userids.value=id;
	cform.employeecode.value=code;
	cform.employeename.value=name;
}


function page_checkpass(){
if(isNullChecked(document.cform.fileids)) 
  {
    alert('<%=message.getMessageDesc("PLEASE_SELECT")%>');
    return;
  }
  if(!confirm("<%=message.getMessageDesc("ZYL_TDR_YESPASS")%>"))return;

  
   cform.tempstatus.value = 41;
 
  cform.actionname.value = "checkpass";
  cform.target = "_self";
  isRunning = true;
  document.cform.submit();
		
}

//getbusinessarea
function page_getpriviceoffice(){
	var objdeptcode=eval("cform.regionid");
	if (objdeptcode==""){
	    return;
	}
	var  datahandler = new  DataHandler();
	datahandler.add_params("regionid" , objdeptcode.value , "Integer");
	datahandler.getResultFromVector("resultproviceoffice","proviceofficename","proviceofficecode","cform.proviceofficelist");
	datahandler.add_job("j_zylmonthsalesdatatwo");
	datahandler.runDataHandler();
  }
  
function page_summary(actionvalue,orderbyname)
{
 if(!checkDate()) return;
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  if(!editform) return;
  editform.action = "MonthSalesDataTwo.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();
}


function page_getbusinessarea(){
	var regionid = cform.regionid.value;
	var objdeptcode = eval("cform.proviceofficelist");
	if (objdeptcode==""){
	    return;
	}
	var  datahandler = new  DataHandler();
	datahandler.add_params("regionid" , regionid, "Integer");
	datahandler.add_params("proviceofficelist" , objdeptcode.value , "String");
	datahandler.getResultFromVector("resultbusinessarea","businessareaname","businessareacode","cform.businessarealist");
	datahandler.add_job("j_zylmonthsalesdatatwo");
	datahandler.runDataHandler();
}

function page_allcheckselect(){
	var allcheck = cform.checkall.checked;
	var alldatafile = document.getElementsByName('fileids');
	var length = alldatafile.length;
	if(allcheck){
		for(var i = 0 ; i < length;i++){
			if(!alldatafile[i].disabled)
			alldatafile[i].checked = true;
		}
	}else{
		for(var i = 0 ; i <= length;i++){
			alldatafile[i].checked = false;
		}	
	}
}

function page_infoYes(id)
{
    popwindow = window.open('MonthSalesDataTwoDetail.jsp?<%= OvalTools.randomURL() %>&tip=1&salesdatafileid='+id,'newwindow', 'height=400, width=1200,top=200,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}

function page_infoDelete(id)
{
    popwindow = window.open('MonthSalesDataTwoDetail.jsp?<%= OvalTools.randomURL() %>&tip=2&salesdatafileid='+id,'newwindow', 'height=400, width=1200,top=200,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function page_checkstatus(id,aid){
	var processtype = 10;
	var checkstatus = document.getElementById(aid).innerText;
	if(popwindow!=null) popwindow.close();
	popwindow = window.open('<%=contextPath%>/phap/phap.datp/masterdata/cm/dataclean/CheckStatus.jsp?<%= OvalTools.randomURL() %>&fileid=' + id + '&processtype=' + processtype + '&checkstatus=' + checkstatus,'newwindow', 'height=400, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function checkDate()
{
	var startdate =document.cform.startdate.value;
	var enddate =document.cform.enddate.value;
	
if (!isEmpty(enddate))
{
  if (toDate(startdate, '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>') > toDate(enddate, '<%=JspHelper.filterNull( session.getAttribute("dateformat") )%>'))
  {
    alert('<%= message.getMessageDesc("DATE1_SHOULD_NOTLATE_THAN_DATE2") %>');
    return false;
  }
  return true;
}
return true;  
}

function page_clear(){
	document.cform.filenamesearch.value="";
	document.cform.customername.value = "";
	document.cform.statusvalue.value="";
	document.cform.customercode.value="";
	document.cform.customername.value="";
	document.cform.areaids.value ="";
	document.cform.businessareaname.value ="";
	document.cform.employeename.value="";
	
}

function popBusinessarea_moulty(){
	if(popwindow!=null) popwindow.close();
	
    url = '<%=contextPath %>/zyl/masterdata/map/SelectAreaTree.jsp?<%= OvalTools.randomURL() %>';
    attribute = 'height=540, width=250,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no';
	popwindow = window.open(url,'newwindow', attribute);
}
function setAreas(areaids,areanames,areacodes){

	document.cform.areaids.value = areaids;
	document.cform.businessareaname.value = areanames;
	//document.cform.businessareacode.value = areacodes;
} 
</script>
</head>
<body>
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<% //--------------------------------------  page location --%>
<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_self">
	<input type="hidden" name="pagename" value="p_zylmonthsalesdatatwo">
	<input type="hidden" name="actionname">
	<custom:hidden property="tempstatus"></custom:hidden>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
  <tr>
    <td>
      <table width="800" border="0" cellspacing="0" onkeydown="if(event.keyCode==13) page_summary('search');" >
      <tr>
      
        	<td><%= label.getLabelName("L_FileName") + label.getLabelName("L_Colon") %></td>
	        <td>
	          	<custom:text property="filenamesearch" size="50" />
	        </td>
	        <td><%= label.getLabelName("L_Status") + label.getLabelName("L_Colon") %></td>
	        <td>
	        <custom:selectdic property ="statusvalue" dictType="ZylStatus" defaultValue="------------------" valueCriteria="35,40,41" defaultValueCost="" />
           </td>
      </tr>
		<tr>
			<td><%= label.getLabelName("L_VendorBusinessName") + label.getLabelName("L_Colon") %></td>
	        <td><custom:text property="customercode" size="10" readonly="true"/>
	            <a onclick="javascript:popCustomer();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
	            <custom:text property="customername" readonly="true" size="30"/>
	            <custom:hidden property="customerid" />
	        </td>

  <%
                SimpleDateFormat formatter1 = new SimpleDateFormat ("yyyy-MM-dd");
                String str_date_end=formatter1.format(new Date());
                
              %>

	<td><%= label.getLabelName("L_TimePeriod") + label.getLabelName("L_Colon") %></td>
	    <td>
                <custom:text property="startdate"  dataType="date"  module="IMG" size="15" />
              <a onclick="javascript:c.show(this,'cform.startdate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
              --
              <%if(pageContext.getAttribute("enddate")==null){%>
			  <custom:text property="enddate" dataType="date" dataFormatName="dateformat" module="IMG" size="15" value="<%=str_date_end %>"/>
			  <%}else{%>
			  <custom:text property="enddate"  dataType="date" dataFormatName="dateformat"  module="IMG"  size="15"/>
			  <%}%>
              <a onclick="javascript:c.show(this,'cform.enddate','yyyy-MM-dd');"><custom:button type="3" label="L_Asterisk" imgsrc="Time.gif" border="0"/></a>
            &nbsp;&nbsp;&nbsp;<a href="javascript:page_summary('search')"><img src="<%= contextPath %>/images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a>
         </td>
				
		</tr>
	  </table>
    </td>
  </tr>
  <tr>
    <td>
		<table width="1000" border="0" cellspacing="0" >
		<tr>
  
        	     <% 
               if (new Integer(1).equals(issalesman)){
	             %> 
	                
	                <td style="width:40px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:40px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:40px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:60px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               <td style="width:60px;">&nbsp;</td><td style="width:150px;">&nbsp;</td>
	               </tr>
	                <%}else{ %>
        	    <tr>
        	    <td  ><%=label.getLabelName("L_BusinessAreaName") +  label.getLabelName("L_Colon") %></td>
			    <td ><custom:hidden  property="areaids" /><custom:text  property="businessareaname"  label="L_BusinessAreaName" readonly="true"/>
			    <a onclick="popBusinessarea_moulty()"><custom:button type="3" value="*"/></a>	
		        </td>
		        <td ><%=label.getLabelName("L_BusinessContact") +  label.getLabelName("L_Colon") %></td>
				<td >
			<custom:text property="employeename" size="20"  />
			<a onClick="javascript:popRep();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a> 
			<custom:hidden property="userids"/>
			<custom:hidden property="employeecode"/>
		   </td>
				<!--
				<td style="20px;"><button type="reset" class="button1" style="width:60"><%=label.getLabelName("L_Clear") %></button></td>
				  -->
			<td>	<button type="button" onclick="page_clear()" class="button1" name="re" value="clear" style="width:60"><%=label.getLabelName("L_Clear") %></button></td>
			<%} %>
        	</tr>
          </table>
           <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td width="3%" class="title_center"><custom:checkbox property="checkall" styleClass="checkbox" onclick="page_allcheckselect()"/></td>
            <td width="27%" class="title_center"><a href="javascript:page_summary('orderby','filename')"><%= label.getLabelName("L_FileName")%></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','createdate')"><%= label.getLabelName("L_CreateDate") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','totalqty')"><%= label.getLabelName("L_TotalData") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','deleteqty')"><%= label.getLabelName("L_DeleteNum") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','deleteqty')"><%= label.getLabelName("L_CheckStatus")%></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','salesrepname')"><%= label.getLabelName("L_SalesRep") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','parentsalesrepname')"><%= label.getLabelName("L_employeenameUp") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_Status") %></a></td>
      
         </tr>
         <%
             int i = 0;
             String strClassType = new String(); 
            
          %>
          <logic:iterate id="summary" collection="<%= searchresults %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            String strIsChecked = new String("");
            
            if(i%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
              
            i++;     
          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
            <td class="title_center">
              <custom:checkbox property="salesdatafileid" styleClass="checkbox" name="summary" changedName="fileids"/>
            </td>
            <td><custom:write property="filename" name="summary"/></td>
            <td><custom:write property="createdate" name="summary" nbsp="true" dataType="date" dataFormat="yyyy-MM-dd"/></td>
            <td><a onclick="page_infoYes('<custom:write property="salesdatafileid" name="summary"/>')"><custom:write property="totalqty" name="summary" nbsp="true"/></a></td>
            <td><A onclick="page_infoDelete('<custom:write property="salesdatafileid" name="summary"/>')"><custom:write property="deleteqty" name="summary" nbsp="true"/></a></td>
            <td><a onclick="page_checkstatus('<custom:write property="salesdatafileid" name="summary"/>','checkstatusrow<%=i %>')" id="checkstatusrow<%=i %>"><custom:write property="checkstatus" name="summary" nbsp="true"/></a></td>
			<td><custom:write property="salesrepname" name="summary" nbsp="true"/></td>
			<td><custom:write property="parentsalesrepname" name="summary" nbsp="true"/></td>
			<td><custom:write property="statusname" name="summary" nbsp="true"/></td>
            <%if(i==1){ %>
            <custom:hidden property="status" name="summary"></custom:hidden>
            <custom:hidden property="status" name="summary" colIndex="<%=new Integer(i-1)%>"></custom:hidden>
            <%}else{ %>
            <custom:hidden property="status" name="summary" colIndex="<%=new Integer(i-1)%>"></custom:hidden>
            <%} %>
          </tr>
          </logic:iterate>
          <input type="hidden" name="numrows" value="<%=searchresults.size()%>"/>
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr>
              <td class="td_center">
              <td class="td_center">
              	<% 
				if(endday.equals("Y")){
				%>
              	<a onclick="page_checkpass();"><custom:button type="1" label="L_CheckPass" imgsrc="Modify.gif" border="0" style="width:100"/></a>
				<% }%>
              </td>
            </tr>
      </table>
    </td>
  </tr>
  </form>
</table>
</body>
<script type="text/javascript">

if(cform.fileids.value!=undefined){
	if(eval('cform.status0').value == "41"){
		cform.fileids.disabled=true;
	}
}
for(var i=0;i<cform.fileids.length;i++){
	if(eval('cform.status'+i).value == "41"){
		cform.fileids[i].disabled=true;
	}
}


</script>
</html>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     